package com.ex.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * 半圆
 * @author thduan
 * 2015-7-14 19:12:47
 */
public class HalfCircleView extends View{
	private static final int DEF_RADIUS = 14;
	private int radius = DEF_RADIUS;
	private Paint mPaint;
	
	public HalfCircleView(Context context) {
		super(context);
		init();
	}
	
	public HalfCircleView(Context context, AttributeSet attrs){
		super(context, attrs);
		init();
	}

	public HalfCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init();
	}
	
	private void init() {
		mPaint = new Paint();
		mPaint.setStyle(Style.FILL);
		mPaint.setColor(Color.BLUE);
		mPaint.setAntiAlias(false);
	}
	
	public void setRadius(int radius) {
		this.radius = radius;
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		RectF rectF = new RectF(0, 0, 2 * radius, 2 * radius);
		canvas.drawArc(rectF, 0, 180, true, mPaint);
	}

}
